package com.example.logisticsservice.Controller;

import com.example.logisticsservice.Constent.Constents;
import com.example.logisticsservice.model.UserInfo;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RequestMapping("/order")
@RestController
public class OrderController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @RequestMapping("createOrder")
    public String createOrder() {
        String orderID = UUID.randomUUID().toString();
        String msg = "订单id：" + orderID;
        rabbitTemplate.convertAndSend("", Constents.WORK_QUEUE, msg);
        return "下单成功";
    }

    @RequestMapping("createOrder2")
    public String createOrder2() {
        String orderID = UUID.randomUUID().toString();
        String msg = "订单id：" + orderID;
        UserInfo userInfo = new UserInfo(orderID, "shangping", 123);
        rabbitTemplate.convertAndSend("", Constents.WORK_QUEUE, userInfo);
        return "下单成功";
    }
}
